from pydantic import Extra

from apitest.engine.client.http import HttpClient
from apitest.engine.const.enums import RType
from apitest.engine.const.model import Auth, EnvModel
from apitest.engine.parse import build_request, build_response
from apitest.lib.ucaccount_lib import model
from apitest.lib.ucaccount_lib.route import UcenterQaDataManagerRoute

PSM = "ucenter.qa.data_manager"


class QaDataManagerService(HttpClient):

    def __init__(self, app: str, auth: Auth = None, env: EnvModel = None, rtype: RType = RType.obj, **kwargs):
        super(QaDataManagerService, self).__init__(app=app, psm=PSM, auth=auth, env=env, **kwargs)
        self.rtype = rtype

    @build_request
    def GetAddSession(self, extra: Extra = Extra.ignore, rtype: RType = None, **kwargs):
        rtype = rtype or self.rtype
        resp = self.client.post(UcenterQaDataManagerRoute.V1UcenterQaSessionDbGetAddKey, **kwargs)
        model.GetAddSessionRsp.Config.extra = extra
        resp = build_response(resp, model.GetAddSessionRsp)
        return resp[rtype]

    @build_request
    def MGetUserByMobile(self, extra: Extra = Extra.ignore, rtype: RType = None, **kwargs):
        rtype = rtype or self.rtype
        resp = self.client.post(UcenterQaDataManagerRoute.V1UcenterQaAccountBaseMgetUserByMobile, **kwargs)
        model.MGetUserIdsByMobilesRsp.Config.extra = extra
        resp = build_response(resp, model.MGetUserIdsByMobilesRsp)
        return resp[rtype]

    @build_request
    def MobileCreateAccount(self, extra: Extra = Extra.ignore, rtype: RType = None, **kwargs):
        rtype = rtype or self.rtype
        resp = self.client.post(UcenterQaDataManagerRoute.V1UcenterQaAccountCreateMobilecreateaccount, **kwargs)
        model.CreateMobile.Config.extra = extra
        resp = build_response(resp, model.CreateMobile)
        return resp[rtype]

    @build_request
    def AddAccountAndGetSession(self, extra: Extra = Extra.ignore, rtype: RType = None, **kwargs):
        rtype = rtype or self.rtype
        resp = self.client.post(UcenterQaDataManagerRoute.V1UcenterQaAccountAddTestAccountGetNewSession, **kwargs)
        model.AddAccountAndGetSessionRsp.Config.extra = extra
        resp = build_response(resp, model.AddAccountAndGetSessionRsp)
        return resp[rtype]

    @build_request
    def GetAllInfo(self, extra: Extra = Extra.ignore, rtype: RType = None, **kwargs):
        rtype = rtype or self.rtype
        resp = self.client.get(UcenterQaDataManagerRoute.V1UcenterQaGetAllDataPoolAttributesAccountInfo, **kwargs)
        model.DataInfoRsp.Config.extra = extra
        resp = build_response(resp, model.DataInfoRsp)
        return resp[rtype]

    @build_request
    def GetAllAccountPool(self, extra: Extra = Extra.ignore, rtype: RType = None, **kwargs):
        rtype = rtype or self.rtype
        resp = self.client.get(UcenterQaDataManagerRoute.V1UcenterQaGetAllDataPoolInfo, **kwargs)
        model.DataInfoRsp.Config.extra = extra
        resp = build_response(resp, model.DataInfoRsp)
        return resp[rtype]

    @build_request
    def GetAllAccountPoolAttributes(self, extra: Extra = Extra.ignore, rtype: RType = None, **kwargs):
        rtype = rtype or self.rtype
        resp = self.client.get(UcenterQaDataManagerRoute.V1UcenterQaGetAllDataPoolAttributesInfo, **kwargs)
        model.DataInfoRsp.Config.extra = extra
        resp = build_response(resp, model.DataInfoRsp)
        return resp[rtype]

    @build_request
    def GetSinglePoolAllInfoWithBaseInfo(self, extra: Extra = Extra.ignore, rtype: RType = None, **kwargs):
        rtype = rtype or self.rtype
        resp = self.client.post(UcenterQaDataManagerRoute.V1UcenterQaGetAllDataSinglePoolAttributesAccountBaseInfo,
                                **kwargs)
        model.GetSinglePoolAllInfoRsp.Config.extra = extra
        resp = build_response(resp, model.GetSinglePoolAllInfoRsp)
        return resp[rtype]

    @build_request
    def DeleteAccountData(self, extra: Extra = Extra.ignore, rtype: RType = None, **kwargs):
        rtype = rtype or self.rtype
        resp = self.client.post(UcenterQaDataManagerRoute.V1UcenterQaAccountBaseDeleteInfo, **kwargs)
        model.DeleteAccountDataRsp.Config.extra = extra
        resp = build_response(resp, model.DeleteAccountDataRsp)
        return resp[rtype]

    @build_request
    def CreateAccount(self, extra: Extra = Extra.ignore, rtype: RType = None, **kwargs):
        rtype = rtype or self.rtype
        resp = self.client.post(UcenterQaDataManagerRoute.V1UcenterQaAccountCreateTestAccount, **kwargs)
        model.CreteAccountRsp.Config.extra = extra
        resp = build_response(resp, model.CreteAccountRsp)
        return resp[rtype]

    @build_request
    def GetAccountInfo(self, extra: Extra = Extra.ignore, rtype: RType = None, **kwargs):
        rtype = rtype or self.rtype
        resp = self.client.post(UcenterQaDataManagerRoute.V1UcenterQaAccountBaseGetInfo, **kwargs)
        model.AccountBaseInfoResp.Config.extra = extra
        resp = build_response(resp, model.AccountBaseInfoResp)
        return resp[rtype]
